﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.FunctionAnalysis
{
	public class LinearTransformedFunction<TInput, TResult, TFunction> : IFunction<TInput, TResult>
		where TFunction : IFunction<TInput, TResult>
	{
		public TResult ResultMultiplied { get; set; }
		public TResult ResultAdded { get; set; }
		public TFunction WrappedFunction { get; set; }
		public LinearTransformedFunction()
		{
			ResultMultiplied = DefaultValueProvider<TResult>.GetValueFromInteger(1);
			ResultAdded = DefaultValueProvider<TResult>.GetZero();
		}


		#region IFunction<TInput,TResult> Members

		public Func<TInput, TResult> Functor
		{
			get { return x => WrappedFunction.Functor(x) * (dynamic)ResultMultiplied + ResultAdded; }
		}

		public IFunction<TInput, TResult> Derivative
		{
			get
			{
				var result = new LinearTransformedFunction<TInput, TResult, IFunction<TInput, TResult>>();
				result.ResultMultiplied = this.ResultMultiplied;
				result.WrappedFunction = this.Derivative;
				return result;
			}
		}

		public IFunction<TInput, TResult> Integral
		{
			get
			{
				var left = new LinearTransformedFunction<TInput, TResult, IFunction<TInput, TResult>>();
				left.ResultMultiplied = this.ResultMultiplied;
				var right = new StandardFunction.Polynomial<TResult>();
				right.SetOrder(1, ResultAdded);  
				return left;
			}
		}

		#endregion
	}
}
